# -*- coding:utf-8 -*-
# @FileName  :utils.py
# @Time      :2020/10/25 14:59
# @Author    :zhoujirong

import parameterized
from common.log import Log
from biz.flow.role import RoleRequest
from biz.cases.base_case import BaseCase
from common.params_operator import Param
from common.utils import get_redis,get_mysql

class TestRole(BaseCase):
    '''角色接口测试用例'''

    data_file_name = 'role_data.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        # cls.mysql = get_mysql()
        cls.cookie = BaseCase().get_token()

    def test_role_create(self):
        '''添加角色'''
        role_name = self.file_data.get('role_name')
        roleType = self.file_data.get('add_roleType')
        description = self.file_data.get('add_description')
        check = self.file_data.get('check_create')
        ret = RoleRequest.role_add(role_name,roleType,description,self.cookie)
        self.assertEqual(check, ret.msg, '返回的的不是操作成功')
        Log.info(ret)

    @parameterized.parameterized.expand(Param.from_excel('role_add.xls'))
    def test_role_create_params(self,name,roleType,description,check,desc):
        self._testMethodDoc = desc
        ret = RoleRequest.role_add(name,roleType,description,self.cookie)
        Log.info(ret)
        self.assertEqual(check, ret.msg)

    def test_role_update(self):
        '''编辑角色'''
        createTime = self.file_data.get('createTime')
        createUser = self.file_data.get('createUser')
        createUsernickname = self.file_data.get('createUsernickname')
        description = self.file_data.get('update_description')
        id = self.file_data.get('id')
        name = self.file_data.get('update_name')
        orgId = self.file_data.get('orgId')
        roleType = self.file_data.get('update_roleType')
        updateTime = self.file_data.get('updateTime')
        updateUser = self.file_data.get('updateUser')
        updateUsernickname = self.file_data.get('updateUsernickname')
        check = self.file_data.get('check_update')
        ret = RoleRequest.role_update(createTime,createUser,createUsernickname,description,id,name,orgId,roleType,updateTime,updateUser,updateUsernickname,self.cookie)
        Log.info(ret)
        self.assertEqual(check,ret.msg)

    def test_getpage(self):
        '''查询接口'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_name = self.file_data.get('search_LIKE_name')
        search_EQ_roleType = self.file_data.get('search_EQ_roleType')
        ret = RoleRequest.role_getpage(curPage,maxSize,search_LIKE_name,search_EQ_roleType,self.cookie)
        Log.info(ret)
        id_list = []
        if ret.list:
            for a in ret.list:
                id_list.append(a.id)
            Log.info(id_list)
        return id_list

    # def test_role_del(self):
    #     '''角色删除，多个项目'''
    #     id_list = TestRole().test_getpage()
    #     if id_list:
    #         ret = RoleRequest.role_del(id_list,cookie)
    #         Log.info(ret)
    #         self.assertEqual('操作成功',ret.msg)
    #     else:
    #         Log.info('无符合筛选条件的角色')




if __name__ == "__main__":
    pass